package Huihu.src.网络编程;

import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

//客户端
public class TcpClient {
    public static void main(String[] args) throws Exception {
        //创建IP地址
        InetAddress inetAddress=InetAddress.getByName("127.0.0.1");
        //创建端口号
        int port=7788;
        //请求连接
        Socket socket=new Socket(inetAddress,port);
        //传输文件
        OutputStream os=socket.getOutputStream();
        FileInputStream is=new FileInputStream("Libs/a.jpg");
        int len;
        while ((len = is.read()) != -1) {
            os.write(len);
        }
        is.close();
        os.close();
        socket.close();
    }
}
